package com.example.authsystem.util;

import com.example.authsystem.dto.UserProfileDto;
import org.springframework.stereotype.Component;

@Component
public class ValidationUtil {

    public void validateUserProfile(UserProfileDto userDto) {
        if (userDto.getUsername() == null || userDto.getUsername().trim().isEmpty()) {
            throw new IllegalArgumentException("用户名不能为空");
        }
        if (userDto.getEmail() == null || !isValidEmail(userDto.getEmail())) {
            throw new IllegalArgumentException("邮箱格式不正确");
        }
    }

    private boolean isValidEmail(String email) {
        return email.matches("^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$");
    }
}
